import axios from '../http'

const api = '/api/shipping-address'
const regionApi = '/api/regions/tree'
const addressDetailApi = '/api/users/receivingInformation/'

const error = (e) => (m) => console.error(e,m);

export function listAddress(cb, fcb = error('listAddress')) {
    axios.get(api).then(response=> {
        cb(response.data);
    }).catch(err=> {
        fcb(err);
    })
}

export function updataDefauleAddress(id,cb, fcb = error('listAddress')) {
    axios.put(api + "/" + id).then(response=> {
        cb(response.data);
    }).catch(err=> {
        fcb(err);
    })
}

export function regionList(cb, fcb = error('regionList')) {
    axios.get(regionApi).then(response=> {
        cb(response.data);
    }).catch(err=> {
        fcb(err);
    })
}


export function saveShippingAddress(params,cb, fcb = error('saveAddress')) {
    axios.post(api,params).then(response=> {
        cb(response.data);
    }).catch(err=> {
        fcb(err);
    })
}

export function updateShippingAddress(id,params,cb, fcb = error('updateShippingAddress')) {
    axios.post(api +"/"+id,params).then(response=> {
        cb(response.data);
    }).catch(err=> {
        fcb(err);
    })
}

export function shippingAddressDetail(params,cb, fcb = error('shippingAddressDetail')) {
    axios.get(api+'/'+params).then(response=> {
        cb(response.data);
    }).catch(err=> {
        fcb(err);
    })
}

export function deleteShippingAddress(params,cb, fcb = error('deleteShippingAddress')) {
    axios.delete(api+'/'+params).then(response=> {
        cb(response.data);
    }).catch(err=> {
        fcb(err);
    })
}


/*
export function orderDetail(params, cb, fcb = error('orderDetail')) {
    axios.get(api + '/' + params.code).then(function (response) {
        cb(response.data);
    }, function (response) {
        var data = false;
        console.info(response);
        fcb(data);
    })
}
*/
